import request from "../request.js"
import store from '@/store/index.js'
import { TOKEN } from '@/constant/index.js'

const base_url = 'https://api.wxls.pro' || 'https://gateway.wxls.pro'

function getToken(){
	const header = { "content-type": "application/json" }
	const yToken = store.getters.yToken || uni.getStorageSync(TOKEN)
	if(yToken){
		header['Authorization'] = `bearer ${yToken}`
	}
	return header
}


/**
 * 获取用户信息
 */
export const info = async () => {
	const header = getToken()
	let { data } = await request({
		url: `${base_url}/auth/user/infoByToken`,
		header,
		method: 'GET'
	});
	if (!data.success) {
		uni.showToast({
			title: data.message || '获取用户信息失败',
			duration: 2000,
			icon: 'none'
		});
		return Promise.reject(new Error(data.message || '获取用户信息失败'))
	}
	return data.data
}